Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HW09 is completed #15

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

HW09 is completed #15

wants to merge 6 commits into from

Conversation

ezhk
Copy link
Owner

@ezhk ezhk commented Aug 22, 2020

Домашнее задание №9 «Генератор валидаторов»

Критерии оценки

  • Закоммичен сгенерированный код - 1 балл
  • Пайплайн зелёный - 3 балла
  • Добавлены новые юнит-тесты (доработаны имеющиеся) в models - до 2 баллов
  • Добавлены юнит-тесты для тулзы в go-validate - до 2 баллов
  • Понятность и чистота кода - до 2 баллов

Зачёт от 7 баллов

@ezhk ezhk changed the title Hw09 generator of validators HW09 is completed Aug 22, 2020
Copy link
Collaborator

@Antonboom Antonboom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://otus.ru/teacher-lk/homework/23752/7007/

Здравствуйте!
Отличная работа.

Принято
10 / 10

}

func ContainsInt(toFind int, searchingString string) bool {
for _, strValue := range strings.Split(searchingString, ",") {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. разделение стоит делать на этапе кодогенерации, чтобы валидатор сразу работал с []string и не тратил время на ресурсы

  2. при желании можно и мапу генерировать, чтобы в целом было O(1). правда N скорее всего мало, так что некритично

}

func (structName User) Validate() ([]ValidationError, error) {
errors := make([]ValidationError, 0)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

if structName.Age < 18 {
errors = append(errors, ValidationError{Field: "Age", Err: fmt.Errorf("invalid Age length")})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

в ошибках не хватает ожидаемых и полученных значений

for _, value := range structName.Phones {

if len(value) != 11 {
errors = append(errors, ValidationError{Field: "Phones", Err: fmt.Errorf("invalid Phones length")})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

в ошибке не хватает информации об индексе элемента

errors = append(errors, ValidationError{Field: "Age", Err: fmt.Errorf("invalid Age length")})
}

if re := regexp.MustCompile("^\\w+@\\w+\\.\\w+$"); re.FindString(string(structName.Email)) == "" {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

в продакшн-ready решении скорее всего пришлось бы компилировать регулярочки заранее (в var, например)

сейчас и так приемлимо.

validatedStruct := ValidateStruct(parsedStruct)
document, err := GenerateDocument(validatedStruct)
if err != nil {
fmt.Println(err)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log.Fatal?


go 1.14

require github.com/stretchr/testify v1.5.1
require (
github.com/fatih/structtag v1.2.0 // indirect
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

где он используется?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants